<template>
	<view class="">
		<!-- <button class="login_btn" @getphonenumber="authLogin" :open-type="opentype()"> -->
			<view
				class="cont_item"
				:class="!listBot ? 'mb-2 shadow rounded_10 p-2' : 'cont_item_bot py-2'"
				v-for="(item, index) of dataList"
				:key="index"
				@click="toIndex(item.id)"
			>
				<view class="flex justify-between w-100">
					<view class="flex" style="width: 83%;">
						<image v-if="!item.company_logo" class="cont_img" src="/static/img2/home/empty_logo.jpg" mode="aspectFit"></image>
						<image v-else class="cont_img" :src="item.company_logo" mode="aspectFit"></image>
						<view class="" style="width: 80%;">
							<view class="cont_t font-weight-bold h4 text_hidden1 text-left">{{ item.company_name }}</view>
							<view class="hot_num flex align-center flex-wrap font-sm">
								<view class="flex mr-2">
									<image src="/static/img2/nav1/hot_icon.png" mode=""></image>
									<text class="h6 font-weight-bold">{{ item.heat_val || 0 }}</text>
								</view>
								<text class="c_9 font_24 mr-2" v-if="exhibitionId">展馆：{{ item.zhanguan || '暂无' }}</text>
								<text class="c_9 font_24 mr-1" v-if="exhibitionId">展位号：{{ item.zhanwei || '暂无' }}</text>
								<text class="c_9 font_24 mr-1" v-else>产品数量：{{ item.company_count || 0 }}</text>
							</view>
						</view>
					</view>
					<view class="cont_head_r flex ml-1" style="width: 16%;">
						<view class="star text-center" @click.stop="collectionChange(item, index)">
							<image v-if="item.qiyeYsc <= 0" src="/static/img2/nav1/collection0.png" mode=""></image>
							<image v-else src="/static/img2/nav1/collection1.png" mode=""></image>
							<text class="c_9 font_24">{{ item.qiyeShouCang }}</text>
						</view>
						<view class="hand_good text-center" @click.stop="goodChange(item, index)">
							<image v-if="item.qiyeYdz <= 0" src="/static/img2/nav1/fabulous0.png" mode=""></image>
							<view v-else>
								<text v-if="item.addanimal" class="add1 h6 c_main font-weight-bolder">+1</text>
								<image src="/static/img2/nav1/fabulous1.png" mode=""></image>
							</view>
							<text class="c_9 font_24">{{ item.qiyeDianZan }}</text>
						</view>
					</view>
				</view>
				<view class="cont_bottom" v-if="item.exhibition_content != 0">
					<view v-if="item.company_desc" class="c_9 text_hidden2 font_24_2">
						<view class="text_hidden2 rich_text text-left mt-2" v-if="item.company_desc">{{ item.company_desc }}</view>
						<rich-text v-else class="text_hidden2 rich_text text-left" :nodes="item.company_content"></rich-text>
					</view>
					<view class="cont_bottom_img flex justify-between mt-1" v-if="item.gold_img1 || item.gold_img2 || item.gold_img3">
						<image :src="item.gold_img1" mode="aspectFill"></image>
						<image :src="item.gold_img2" mode="aspectFill"></image>
						<image :src="item.gold_img3" mode="aspectFill"></image>
					</view>
				</view>
				<view v-if="item.prize_name" class="top_tag px-1 font_22" @click.stop="goPages('/subPages/web_view_h5/index?url=' + item.prize_url)">{{ item.prize_name }}</view>
				<!-- <image v-if="item.prize_name" class="gnb_img" src="/static/img2/home/gnb.png" mode="aspectFill"></image> -->
				<!-- <text class="to_home text-white h6">去主页</text> -->
				<!-- <text class="bot_tag bg_main font_22 text-white px-1" v-if="item.prize_name" @click.stop="goPages('/subPages/web_view_h5/index?url='+item.prize_url)">{{item.prize_name}}></text> -->
			</view>
		<!-- </button> -->
	</view>
</template>

<script>
import { likecollectionDzsc } from '@/api/home/company.js';
export default {
	props: {
		list: {
			type: Array,
			default: function() {
				return [];
			}
		},
		listBot: {
			type: String,
			default: ''
		},
		checkTypes: {
			type: String,
			default: 'qy'
		},
		exhibitionId: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			dataList: [],
			userId: '', //用户id
			companyVal: null
		};
	},
	watch: {
		list(newV, oldV) {
			this.dataList = newV;
		},
		dataList: {
			handler(newV, oldV) {
				this.dataList = newV;
			},
			deep: true
		}
	},
	computed: {
		opentype() {
			return function(val) {
				return !uni.getStorageSync('userInfo').hasLogin ? 'getPhoneNumber' : '';
			};
		}
	},
	mounted() {
		// console.log("==",this.list);
		this.userId = uni.getStorageSync('userInfo').userId;
		this.dataList = this.list;
	},
	methods: {
		// 收藏
		collectionChange(val, idx) {
			let typesc = this.checkTypes == 'qy' ? 1 : 3;
			let isSc = val.qiyeYsc == 0 ? 1 : 2;
			this.dzscChange(typesc, isSc, val.id, idx);
		},
		// 点赞
		goodChange(val, idx) {
			let typedz = this.checkTypes == 'qy' ? 2 : 4;
			let isDz = val.qiyeYdz == 0 ? 1 : 2;
			this.dzscChange(typedz, isDz, val.id, idx);
		},
		dzscChange(type, status, contId, index) {
			if (!uni.getStorageSync('userInfo').hasLogin) {
				this.toLogin(); // 未登录
			} else {
				let msg = {
					zhanhui_id: this.exhibitionId,
					checktype: 2,
					type: type,
					status: status,
					company_product_id: contId,
					uid: this.userId
				};
				likecollectionDzsc(msg)
					.then(res => {
						if (res.code == 0) {
							uni.$u.toast(res.msg);
							let sc = parseInt(this.dataList[index].qiyeShouCang),
								dz = parseInt(this.dataList[index].qiyeDianZan);
							if (type == 1 || type == 3) {
								var add = sc + 1,
									minus = sc == 0 ? sc : sc - 1;
								this.$set(this.dataList[index], 'qiyeYsc', status == 1 ? 1 : 0);
								this.$set(this.dataList[index], 'qiyeShouCang', status == 1 ? add : minus);
							} else {
								var add = dz + 1,
									minus = dz - 1;
								this.$set(this.dataList[index], 'qiyeYdz', status == 1 ? 1 : 0);
								this.$set(this.dataList[index], 'qiyeDianZan', status == 1 ? add : minus);
								this.$set(this.dataList[index], 'addanimal', true);
							}
							this.$set(this.dataList[index], 'heat_val', res.heat_val.heat_val);
							// console.log('热力值', this.dataList);
						} else {
							uni.$u.toast(res.msg);
						}
					})
					.catch(err => {
						console.log('点赞或收藏失败', err);
						uni.$u.toast('点赞或收藏失败');
					});
			}
		},
		// 去主页
		toIndex(val) {
			this.companyVal = val;
			// if (!uni.getStorageSync('userInfo').hasLogin) return;
			uni.navigateTo({
				url: '/subPages/company_home/index?id=' + val + '&exhibitionId=' + this.exhibitionId
			});
		},
		// 点击列表未登录先拉起登录后再跳转
		authLogin(e) {
			if (uni.getStorageSync('userInfo').hasLogin) return;
			if (e.detail.errMsg === 'getPhoneNumber:ok') {
				this.getLogin(e.detail.code)
					.then(res => {
						uni.$u.toast('授权登录成功');
						this.toIndex(this.companyVal);
					})
					.catch(err => {
						console.log('登录失败');
					});
			} else {
				uni.showToast({
					title: '授权失败,请登录后查看',
					icon: 'none'
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.cont_item:last-child {
	border: 0;
}

.cont_item_bot {
	border-bottom: 1px solid #d1d1d1;
}

.cont_item {
	background-color: $color2;
	position: relative;
	overflow: hidden;

	.cont_img {
		margin-right: 15rpx;
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
	}

	.hot_num {
		line-height: 42rpx;

		image {
			width: 21rpx;
			height: 26rpx;
			display: inline;
			margin-right: 5rpx;
			margin-top: 10rpx;
		}
	}

	.cont_head_r {
		image {
			width: 44rpx;
			height: 44rpx;
			border-radius: 0;
		}

		.star {
			margin-right: 15rpx;
		}

		.hand_good {
			position: relative;

			.add1 {
				position: absolute;
				top: 0rpx;
				left: 0;
				z-index: 999;
				opacity: 0;
				animation: mygood 3s linear 0s 1 normal running;
			}

			@keyframes mygood {
				0% {
					top: -10rpx;
					opacity: 0.5;
				}

				50% {
					top: -50rpx;
					opacity: 1;
				}

				100% {
					top: -60rpx;
					opacity: 0;
				}
			}
		}
	}

	.cont_bottom_img {
		image {
			width: 215rpx;
			height: 128rpx;
			border-radius: 15rpx;
		}
	}

	.to_home {
		background-color: $color14;
		border-radius: 15rpx;
		padding: 0rpx 30rpx;
		position: absolute;
		bottom: -27rpx;
		left: 50%;
		margin-left: -70rpx;
	}

	.top_tag {
		position: absolute;
		top: 0;
		left: 0;
		border-bottom-right-radius: 20rpx;
		background-image: linear-gradient(#ffac4b, #ffe2ab, #e6b64f);
		color: #ab7220;
		line-height: 35rpx;
	}

	// .gnb_img {
	// 	width: 200rpx;
	// 	height: 200rpx;
	// 	position: absolute;
	// 	right: 30rpx;
	// 	top: 50%;
	// 	margin-top: -100rpx;
	// 	overflow-y: hidden;
	// 	z-index: 0;
	// }
}

::v-deep rich-text {
	line-height: 42rpx;
}
</style>
